<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
    <title>修改密码</title>
    <script type="text/javascript" src="../../js/mui.min.js"></script>  
    <script type="text/javascript" src="../../js/common.js"></script>
    <script type="text/javascript" src="../../js/jquery-1.11.3.js" ></script>
    <link rel="stylesheet" href="../../css/mui.min.css" />
    <link rel="stylesheet" href="../../css/own.css" />
    <script type="text/javascript">
    	mui.init();
    	mui.plusReady(function(){
    		document.getElementById("back").addEventListener("tap",function(){
    			history.back();
    		});
    		document.getElementById("telBtn").addEventListener("tap",function(){
    			mui.callService();
    		});
    		document.getElementById("code").addEventListener("tap",function(){
    			
    			getCode();
    		});
    		document.getElementById("pwSet").addEventListener("tap",function(){
    			pwSet();
    		});
    		
    		//从缓存获取手机号码
    		var user_mobile=mui.cacheUser.get("user_mobile");
    		document.getElementById("account_phone").value=user_mobile;
    		document.getElementById("password").value="";
			document.getElementById("password_confirm").value="";//新密码
			document.getElementById("email").value="";//确认密码
    	
    	});
    	
    	//获取验证码
    	function getCode(){
    		var mobile=document.getElementById("account_phone").value;
    		//这里要对手机号码进行格式校验
    		var paramUrl={
				url:"../login/login.html"
			}
    		if(!tzdr.validate_mobile(mobile)||mui.isnull(mobile)){
    			mui.toast("手机号码不正确");
    			return;
    		}
			
    		mui.app_request('sms',{ 
      			 'mobile':mobile,
			    'type':2   
      		},function(result){
      			
      				mui.toast("发送成功！"); 
      				var o=document.getElementById("code");
		  			tzdr.smsTime(o); 
      				return;
      				
      		},function(result){
      			if(result.code==2){
      				mui.toast("短信验证码发送失败！");
      				return;
      			}else if(result.code==5){
      				mui.toast("操作过于频繁，请稍后再试！");
      				return;
      			}else if(result.code==4){
      				mui.toast("手机号码不存在！");
      				return;
      			}else{
      				mui.toast("系统繁忙，请稍后再试！");
      				return;
      			}
      		},paramUrl);
    	}
    	
    	
    	function pwSet(){
    		var mobile=document.getElementById("account_phone").value;
			var code=document.getElementById("password").value;
			var password=document.getElementById("password_confirm").value;//新密码
			var password2=document.getElementById("email").value;//确认密码
			var paramUrl={
				url:"../login/login.html"
			}
			//这里要对手机号码进行格式校验
    		if(!tzdr.validate_mobile(mobile)||mui.isnull(mobile)){
    			mui.toast("手机号码不正确");
    			return;
    		}
			if(mui.isnull(code)){
				mui.toast("短信验证码错误！");
				return;
			}

			if(mui.isnull(password)){
				mui.toast("密码由6-16位数字和字母组成。");
				return;
			}
			if(mui.isnull(password2)){
				mui.toast("两次输入的密码不一致！");
				return;
			}
			
			if(!tzdr.validate_password(password)){
				mui.toast("密码由6-16位数字和字母组成。");
				return;
			}
			//校验新密码与确认密码是否一致
			if(password!=password2){
				mui.toast("两次输入的密码不一致！");
				return;
			}
			
			mui.app_request('/reset_password',{ 
      			 'mobile':mobile,
			    'code':code,
			    'password':password
      		},function(result){
      				updateMockAccount(mobile,password);
      				mui.toast("密码重置成功，请重新登录！");
      				mui.cacheUser.clear();
      				plus.storage.removeItem("isRealName");
			      	plus.storage.removeItem("inviteUrl"); 
      				var lo=plus.webview.getWebviewById("login");
			  		if(lo){
			  			mui.app_refresh("login"); 
			  		}else{ 
			  			mui.openWindow("../login/login.html",'login');
			  		}
      				return;
      			
      		},function(result){
      			if(result.code==2){
      				mui.toast("重置失败！");
      				return;
      			}else if(result.code==6){
      				mui.toast("密码格式有误！");
      				return;
      			}else if(result.code==5){
      				mui.toast("验证码错误或为空！");
      				return;
      			}else if(result.code==4){
      				mui.toast("验证码失效！");
      				return;
      			}else if(result.code==3){
      				mui.toast("用户信息不存在！");
      				return;
      			}else{
      				mui.toast("系统繁忙，请稍后再试！");
      				return;
      			}
      			
      		},paramUrl);
    	};
    	tzdr.online();
    </script>
</head>
<body>
	<header class="mui-bar mui-bar-nav own-topbg">
		<a class="mui-action-back mui-icon mui-icon-left-nav mui-pull-left" id="back"><i>返回</i></a>
		<h1 class="mui-title">修改密码</h1>		
		<a href="javascript:void(0)" class="top-tel" id="online">在线客服</a>
	</header>
	<!--<nav class="navlist">
		<a href="javascript:void(0);" id="product">
			<span class="mui-icon mui-icon-list"></span>
			<span class="mui-tab-label">产品</span>
		</a>
		<a class="" href="javascript:void(0);"  id="scheme">
			<span class="mui-icon mui-icon-compose"></span>
			<span class="mui-tab-label">方案</span>
		</a>
		<a  class="navon"  id="account" href="javascript:void(0);">
			<span class="mui-icon mui-icon-contact mui-icon-icon-contact-filled"></span>
			<span class="mui-tab-label" >账户</span>
		</a>
	</nav>-->
	<div class="mui-content">
		<form class="mui-input-group ac_tel">
			<div class="mui-input-row">
				<label>手机号码</label>
				<input id='account_phone' type="tel" readonly="readonly" disabled="disabled" class="mui-input-clear mui-input" placeholder="">
			</div>
			<div class="mui-input-row">
				<label>短信验证</label>
				<input id='password' type="tel" class="mui-input" placeholder="请输入验证码" maxlength="6">
				<button class="lg_codebtn" id="code" type="button">获取验证码</button>
			</div>
			<div class="mui-input-row">
				<label>设置新密码</label>
				<input id='password_confirm' type="password" class="mui-input-clear mui-input" placeholder="6-16位数字和字母组成">
			</div>
			<div class="mui-input-row">
				<label>确认新密码</label>
				<input id='email' type="password" class="mui-input-clear mui-input" placeholder="">
			</div>
		</form>
		<div class="mui-content-padded">
			<button class="mui-btn mui-btn-block lg-btnlogin" id="pwSet">确认</button>
		</div>
	</div>
</body>
</html>